package com.huike.pmps.config.lifecycle;

import com.huike.pmps.model.constants.GlobalConstants;
import com.huike.pmps.model.entity.Dictionary;
import com.huike.pmps.service.DictionaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 作者：谌贵斌(黑桃K)
 * 日期: 2888-08-08
 * 老师QQ: 272488352
 * 官方QQ交流群: 377748272
 * 刀客程序员官网：http://www.daoke360.com
 * 刀客程序员淘宝旗舰店：https://daoke360.taobao.com/
 */

@Component
@Slf4j
public class ApplicationRunnerImpl implements ApplicationRunner {

    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    DictionaryService dictionaryService;

    /**
     * springboot启动后执行该方法，加载数据字典进入redis中
     * @param args
     * @throws Exception
     */
    @Override
    public void run(ApplicationArguments args) throws Exception {
       /* //将字典数据存入redis
        List<Dictionary> dictionaries = dictionaryService.selectList();
        for (Dictionary dictionary : dictionaries) {
            redisTemplate.opsForHash().put(GlobalConstants.REDIS_HASH_DICTIONARY_DATA, dictionary.getId(), dictionary.getName());
        }
        log.info("成功加载数据字典到redis中");*/
    }
}
